//
//  CityTourVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/5/31.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "CityTourVC.h"
#import "CityTourCell.h"
@interface CityTourVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UIView * tableViewHeaderView;
@property (nonatomic, strong)UIImageView * headerImageView;
@property(nonatomic, strong)UITableView * tableView;
@property(nonatomic, strong)NSMutableArray * dataSource;
@property (nonatomic, strong)UILabel * titleLabel;
@end

@implementation CityTourVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.view.backgroundColor = cyColor;
    self.barBGAlpha = 0;
    [self createTabelView];
    [self setupTableViewHeaderView];
}

- (void)setTitle:(NSString *)title {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:18 weight:10];
        self.navigationItem.titleView = _titleLabel;
    }
    _titleLabel.text = title;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:0];
}

- (UIView *)tableViewHeaderView {
    if (!_tableViewHeaderView) {
        _tableViewHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH,SCREEN_HEIGHT /3)];
        _tableViewHeaderView.backgroundColor = [UIColor clearColor];
    }
    return _tableViewHeaderView;
}

- (void)setupTableViewHeaderView {
    self.headerImageView.image = [UIImage imageNamed:@"placeholder_rec"];
    [self.tableViewHeaderView addSubview:self.headerImageView];
}

- (UIImageView *)headerImageView {
    if (!_headerImageView) {
        _headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT /3)];
        _headerImageView.clipsToBounds = YES;
        _headerImageView.contentMode = UIViewContentModeScaleToFill;
        
    }
    
    return _headerImageView;
}
- (void)createTabelView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    //self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableHeaderView = self.tableViewHeaderView;
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"CityTourCell" bundle:nil] forCellReuseIdentifier:@"CityTourCell"];
    
}



#pragma mark -UITableViewDelegate,UITableViewDataSource


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat yOffset = self.tableView.contentOffset.y;
    CGFloat H = SCREEN_HEIGHT/3;
    if (yOffset <= 0) {
        
        CGFloat factor = -yOffset + H ;
        CGRect f = CGRectMake(- (SCREEN_WIDTH * factor/H - SCREEN_WIDTH)/2, yOffset, SCREEN_WIDTH *factor/H, factor);
        self.headerImageView.frame = f;
    }
    
    if (yOffset <= SCREEN_HEIGHT/3 - 74 ) {
        
        CGFloat aplha = yOffset /(SCREEN_HEIGHT/3 - 74);
        
        [[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:aplha];
        self.titleLabel.alpha = aplha;
        
    }else {
        if (!_titleLabel) {
            self.title = MYLocalizedString(@"CITYTOURLIST_TITLE", nil);
        }
        [[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:1];
        self.titleLabel.alpha = 1;
    }

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CityTourCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CityTourCell"];
    
    
    
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 0.0000001;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  270;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
